<template>
	<div class="app-container">
		<el-form :model="queryParams" ref="queryForm" :inline="true" label-width="68px">
			<el-form-item label="活动名称" prop="name">
				<el-input v-model="queryParams.name" placeholder="请输入活动名称" clearable size="small" @keyup.enter.native="handleQuery" />
			</el-form-item>
			<el-form-item>
				<el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
				<el-button type="primary" icon="el-icon-search" size="mini" @click="resetQuery">重置</el-button>
			</el-form-item>
		</el-form>

		<el-row :gutter="10" class="mb8">
			<el-col :span="1.5">
				<el-button type="primary" icon="el-icon-plus" size="mini" @click="handleAdd" v-hasPermi="['system:company:add']">新增
				</el-button>
			</el-col>
		</el-row>

		<el-table v-loading="loading" :data="companyList" @selection-change="handleSelectionChange" row-key="id">
			<el-table-column label="活动id"  prop="id" >
			</el-table-column>
      <el-table-column label="活动编码"  prop="rule" >
      </el-table-column>
      <el-table-column label="立减金"  prop="score" >
      </el-table-column>
			<el-table-column label="活动名称" prop="name" >
				<template slot-scope="scope">
					<template v-if="!scope.row.isChild">{{scope.row.name}}</template>
					<template v-else>
						<div style="display: block;position:absolute;left: 0;top: 0;width: calc(100%);height: calc(100%);background-color: #fff;" v-if="scope.row.isLast"></div>
						<div style="display: block;position:absolute;left: 0;top: 0;width: calc(100%);height: calc(100% + 1px);background-color: #fff;" v-else></div>
					</template>
				</template>
			</el-table-column>
			<el-table-column label="开始时间" align="center" prop="startTime" >
				<template slot-scope="scope">
					<template v-if="!scope.row.isChild">{{scope.row.startTime}}</template>
					<template v-else>
						<div style="display: block;position:absolute;left: 0;top: 0;width: calc(100% + 1px);height: calc(100%);background-color: #fff;" v-if="scope.row.isLast"></div>
						<div style="display: block;position:absolute;left: 0;top: 0;width: calc(100% + 1px);height: calc(100% + 1px);background-color: #fff;" v-else></div>
					</template>
				</template>
			</el-table-column>
			<el-table-column label="结束时间" align="center" prop="finishTime" >
				<template slot-scope="scope">
					<template v-if="!scope.row.isChild">{{scope.row.finishTime}}</template>
					<template v-else>
						<div style="display: block;position:absolute;left: 0;top: 0;width: calc(100% + 1px);height: calc(100%);background-color: #fff;" v-if="scope.row.isLast"></div>
						<div style="display: block;position:absolute;left: 0;top: 0;width: calc(100% + 1px);height: calc(100% + 1px);background-color: #fff;" v-else></div>
					</template>
				</template>
			</el-table-column>
			<el-table-column label="操作" align="center" class-name="small-padding fixed-width">
				<template slot-scope="scope">
					<template v-if="!scope.row.isChild">
						<el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)" v-hasPermi="['system:company:edit']">修改</el-button>
<!--						<el-button size="mini" type="text" icon="el-icon-money" @click="handleDictUpdate(scope.row)">配置立减金</el-button>-->
						<el-button size="mini" type="text" icon="el-icon-money" @click="copy(scope.row)">复制活动地址</el-button>
<!--						<el-button size="mini" type="text" icon="el-icon-s-ticket" @click="handleExchange(scope.row.id)" v-hasPermi="['system:company:remove']">兑换码</el-button>-->
						<el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)" v-hasPermi="['system:company:remove']">删除</el-button>
					</template>
					<template v-else>
						<div style="display: block;position:absolute;left: 0;top: 0;width: calc(100%);height: calc(100%);background-color: #fff;" v-if="scope.row.isLast"></div>
						<div style="display: block;position:absolute;left: 0;top: 0;width: calc(100%);height: calc(100% + 1px);background-color: #fff;" v-else></div>
					</template>
				</template>
			</el-table-column>
		</el-table>

		<pagination v-show="total>0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize" @pagination="getList" />

		<!-- 添加或修改【请填写功能名称】对话框 -->
		<el-dialog :title="title" :visible.sync="open" width="500px">
			<el-form ref="form" :model="form" :rules="rules" label-width="100px">
				<el-form-item label="活动名称" prop="name">
					<el-input v-model="form.name" placeholder="请输入活动名称" maxlength="15" />
				</el-form-item>
        <el-form-item label="活动编码" prop="rule">
          <el-input v-model="form.rule" placeholder="请输入活动编码" maxlength="15" />
        </el-form-item>
        <el-form-item label="立减金" prop="score">
          <el-input v-model="form.score" placeholder="请输入立减金" maxlength="15" />
        </el-form-item>
				<el-form-item label="开始时间" prop="startTime">
					<el-date-picker :picker-options="pickerOptionsStart" clearable size="small" style="width: 200px" v-model="form.startTime" type="datetime" value-format="yyyy-MM-dd HH:mm:ss" placeholder="选择开始时间">
					</el-date-picker>
				</el-form-item>
				<el-form-item label="结束时间" prop="finishTime">
					<el-date-picker :picker-options="pickerOptionsEnd" clearable size="small" style="width: 200px" v-model="form.finishTime" type="datetime" value-format="yyyy-MM-dd HH:mm:ss" placeholder="选择结束时间">
					</el-date-picker>
				</el-form-item>
			</el-form>
			<div slot="footer" class="dialog-footer">
				<el-button type="primary" @click="submitForm">确 定</el-button>
				<el-button @click="cancel">取 消</el-button>
			</div>
		</el-dialog>

		<el-dialog :visible.sync="userOpen" :model="userParams" ref="userForm" width="800px">
			<el-form :inline="true" label-width="80px">
				<el-form-item label="姓名" prop="userName">
					<el-input v-model="userParams.userName" placeholder="请输入姓名" clearable size="small" @keyup.enter.native="handleQuery" />
				</el-form-item>
				<el-form-item label="手机号码" prop="phone">
					<el-input v-model="userParams.phone" placeholder="请输入手机号码" clearable size="small" @keyup.enter.native="handleQuery" />
				</el-form-item>
				<el-form-item label="支行" prop="branch">
					<el-input v-model="userParams.branch" placeholder="请输入支行" clearable size="small" @keyup.enter.native="handleQuery" />
				</el-form-item>
				<el-form-item label="网点" prop="outlets">
					<el-input v-model="userParams.outlets" placeholder="请输入网点" clearable size="small" @keyup.enter.native="userHandleQuery" />
				</el-form-item>
				<el-form-item label="城市" prop="areaName">
					<el-input v-model="userParams.areaName" placeholder="请输入城市" clearable size="small" @keyup.enter.native="userHandleQuery" />
				</el-form-item>
				<el-form-item>
					<el-button type="primary" icon="el-icon-search" size="mini" @click="userHandleQuery">搜索</el-button>
				</el-form-item>
			</el-form>
			<div>
				<span>已选中id：</span>
				<el-tag v-for="(item, index) in userIdsObj" :key="index" style="margin: 0 20px 20px 0;">{{item.userName || item}}</el-tag>
			</div>
			<el-table :data="userList" ref="multipleTable" height="500" tooltip-effect="dark" @select="handleUserSelectionChange1" @select-all="handleUserSelectionChange2">
				<el-table-column type="selection" width="55" align="center" />
				<el-table-column label="姓名" align="center" prop="userName" />
				<el-table-column label="手机号码" align="center" prop="phone" />
				<el-table-column label="支行" align="center" prop="branch" />
				<el-table-column label="网点" align="center" prop="outlets" />
				<el-table-column label="城市" align="center" prop="areaName" />
			</el-table>
			<div slot="footer" class="dialog-footer dialog-footer1" v-if="userOpen">
				<el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-page="userParams.pageNum" :page-sizes="[10, 100, 1000, 5000, 10000]" :page-size="userParams.pageSize" layout="total, sizes, prev, pager, next" :total="userParams.tatal">
				</el-pagination>
				<div>
					<el-button type="primary" @click="submitUserForm">确 定</el-button>
					<el-button @click="userCancel">取 消</el-button>
				</div>
			</div>
		</el-dialog>

		<el-dialog :visible.sync="dictOpen" width="800px">
			<el-form :inline="true" label-width="80px" :model="dictParams" ref="dictForm">
				<el-form-item label="字典标签" prop="dictLabel">
					<el-input v-model="dictParams.dictLabel" placeholder="请输入字典标签" clearable size="small" @keyup.enter.native="dictHandleQuery" />
				</el-form-item>
				<el-form-item>
					<el-button type="primary" icon="el-icon-search" size="mini" @click="dictHandleQuery">搜索</el-button>
					<el-button type="primary" icon="el-icon-search" size="mini" @click="resetDictQuery">重置</el-button>
					<el-button type="primary" icon="el-icon-search" size="mini" @click="$router.push({ path: '/dict/type/data/24'})">新增字典标签</el-button>
				</el-form-item>
			</el-form>
			<el-table :data="dictList" ref="multipleTables" height="500" tooltip-effect="dark" @selection-change="handleDictSelectionChange">
				<el-table-column type="selection" width="55" align="center" />
				<el-table-column label="字典编码" align="center" prop="dictCode" />
				<!--				<el-table-column label="权重" align="center" prop="chance" width="180" v-if="choiceFlag == '1'">-->
				<!--					<template slot-scope="scope">-->
				<!--						<input type="text" v-model="scope.row.chance" style="width: 90%;">-->
				<!--					</template>-->
				<!--				</el-table-column>-->
				<el-table-column label="字典标签" align="center" prop="dictLabel" />
				<el-table-column label="字典键值" align="center" prop="dictValue" />
				<el-table-column label="字典排序" align="center" prop="dictSort" />
				<el-table-column label="状态" align="center" prop="status" :formatter="statusFormat" />
				<el-table-column label="金额" align="center" prop="remark"  />
				<el-table-column label="创建时间" align="center" prop="createTime" width="180">
					<template slot-scope="scope">
						<span>{{ parseTime(scope.row.createTime) }}</span>
					</template>
				</el-table-column>
			</el-table>
			<div slot="footer" class="dialog-footer">
				<el-button type="primary" @click="submitDictForm">投放数量</el-button>
				<el-button @click="dictCancel">取 消</el-button>
			</div>
		</el-dialog>

		<el-dialog :visible.sync="dictNumOpen" ref="dictNumForm" width="800px">

			<el-table :data="dictNumData" height="400" tooltip-effect="dark">
				<el-table-column label="字典标签" align="center" prop="dictLabel" />
				<el-table-column label="立减金金额" align="center" prop="remark" :show-overflow-tooltip="true" />
				<el-table-column label="投放数量" align="center">
					<template slot-scope="scope">
						<el-input-number :min="1" :max="50000" v-model="scope.row.num" />
					</template>
				</el-table-column>
			</el-table>
			<div slot="footer" class="dialog-footer">
				<el-button type="primary" @click="submitDictNumForm">确 定</el-button>
				<el-button @click="dictNumCancel">取 消</el-button>
			</div>
		</el-dialog>
	</div>
</template>

<script>
import
{
	listCompany,
	getCompany,
	delCompany,
	addCompany,
	updateCompany,
	exportCompany,
	getBankUsers,
	getBankDicts,
	addBankUser, addBankDict, addBankDicts, createCompanyCode
} from "@/api/system/company";
import { listBank, getBank, delBank, addBank, updateBank, exportBank } from "@/api/system/bank";
import { getToken } from "@/utils/auth.js";
import { listData, getData, delData, addData, updateData } from "@/api/system/dict/data";
import { parse } from 'path-to-regexp';

export default {
	name: "Company",
	data()
	{
		return {
			pickerOptionsStart: {
				disabledDate: (time) =>
				{
					if (this.form.finishTime)
					{
						return (
							time.getTime() >= new Date(this.form.finishTime).getTime()
						);
					}
				}
			},
			pickerOptionsEnd: {
				disabledDate: (time) =>
				{
					if (this.form.startTime)
					{
						return (
							time.getTime() <= new Date(this.form.startTime).getTime()
						);
					}
				}
			},
			fileList: [],
			// //上传headers
			headers: {
				'Authorization': null
			},
			url: null,
			// 遮罩层
			loading: true,
			// 日期范围
			// dateRange: [],
			// 选中数组
			ids: [],
			userIds: [],
			userIdsObj: [],
			dictIds: [],
			choiceFlag: 1,
			statusOptions: [],
			// 非单个禁用
			single: true,
			// 非多个禁用
			multiple: true,
			// 总条数
			total: 0,
			// 【请填写功能名称】表格数据
			companyList: [],
			userList: [],
			dictList: [],
			dictNumData: [],
			//活动状态
			disableOptions: [],
			// 弹出层标题
			title: "",
			// 是否显示弹出层
			open: false,
			userOpen: false,
			dictOpen: false,
			dictNumOpen: false,
			// 查询参数
			queryParams: {
				pageNum: 1,
				pageSize: 10,
				detail: undefined,
				type: undefined,
				score: undefined,
				chance: undefined,
				name: undefined,
				rule: undefined,
				rewards: undefined,
				disable: undefined,
				startTime: undefined,
				finishTime: undefined
			},
			// 查询参数
			userParams: {
				pageNum: 1,
				pageSize: 10,
				tatal: null,
				companyId: undefined,
				userName: undefined,
				phone: undefined,
				branch: undefined,
				outlets: undefined,
				areaName: undefined,
			},
			dictParams: {
				pageNum: 1,
				pageSize: 1000000,
				dictLabel: undefined,
				status: 0,
				dictType: 'sys_bussiness_type'
			},
			// 表单参数
			form: {},
			// 表单校验
			rules: {
				name: [
					{ required: true, message: "活动名称不能为空", trigger: "blur" }
				],
        score: [
          { required: true, message: "立减金不能为空", trigger: "blur" }
        ],
        chance: [
          { required: true, message: "单人领取次数不能为空", trigger: "blur" }
        ],
				startTime: [
					{ required: true, message: "开始时间不能为空", trigger: "blur" }
				],
				finishTime: [
					{ required: true, message: "结束时间不能为空", trigger: "blur" }
				],
				rule: [ { required: true, message: "图标不能为空", trigger: "blur" } ]
			},
			configForm: {
				companyId: null,
				dictCode: null,
				nums: null
			}
		};
	},
	watch: {
		userIds()
		{
			let arr = JSON.parse(JSON.stringify(this.userIds))
			arr.forEach((v1, index) =>
			{
				this.userIdsObj.forEach(v2 =>
				{
					if (v1 === v2.bankUserId)
					{
						arr[ index ] = v2
					}
				})
				this.userList.forEach(v3 =>
				{
					if (v1 === v3.bankUserId)
					{
						arr[ index ] = v3
					}
				})
			})
			this.userIdsObj = arr
		}
	},
	created()
	{
		this.getList();
		this.getUrl()
		this.getDicts("sys_yes_no").then(response =>
		{
			this.disableOptions = response.data;
		});
		this.getDicts("sys_normal_disable").then(response =>
		{
			this.statusOptions = response.data;
		});
	},
	methods: {
		handleSizeChange(val)
		{
			this.userParams.pageSize = val
			this.handleUserUpdate1()
		},
		copy(data)
		{
			let url = "http://test.zechaoxinxi.com/exchangeweb/?companyId=" + data.id;
			let oInput = document.createElement('input')
			oInput.value = url
			document.body.appendChild(oInput)
			oInput.select() // 选择对象
			document.execCommand("Copy") // 执行浏览器复制命令
			this.$message({
				message: '复制成功',
				type: 'success'
			})
			oInput.remove()
		},
		handleCurrentChange(val)
		{
			this.userParams.pageNum = val
			this.handleUserUpdate1()
		},
		/** 查询【请填写功能名称】列表 */
		getList()
		{
			this.loading = true;
			listCompany(this.queryParams).then(response =>
			{

				response.rows.forEach(row =>
				{
					if (row.money && row.total)
					{
						let money = row.money.split(','),
							total = row.total.split(','),
							size = money.length;

						if (size > 1)
						{
							row.children = row.children || [];

							for (let i = 1; i < size; i++)
							{
								row.children.push({
									id: row.id + '-' + i,
									money: money[ i ],
									total: total[ i ],
									isChild: true,
									isLast: i === size - 1
								});
							}

							row.money = money[ 0 ];
							row.total = total[ 0 ];
						}
					}
				});

				this.companyList = response.rows;
				this.total = response.total;
				this.loading = false;
			});
		},
		disableFormat(row, column)
		{
			return this.selectDictLabel(this.disableOptions, row.disable);
		},
		disableFormat1(row, column)
		{
			return this.selectDictLabel(this.disableOptions, row.send);
		},
		disableFormat2(row, column)
		{
			return this.selectDictLabel(this.disableOptions, row.choice);
		},
		statusFormat(row, column)
		{
			return this.selectDictLabel(this.statusOptions, row.status);
		},
		getUrl()
		{
			let url = process.env.VUE_APP_BASE_API + '/common/createOSS'
			this.url = url
			this.headers.Authorization = 'Bearer ' + getToken() // 让每个请求携带自定义token 请根据实际情况自行修改
		},
		handleExceed(files, fileList)
		{
			this.$message.warning(`当前限制选择 1 个文件，本次选择了 ${files.length} 个文件，共选择了 ${files.length + fileList.length} 个文件`);
		},
		handleImageSuccess(res, file, fileList)
		{
			this.form.rule = fileList[ 0 ].response.url
		},
		handleRemove(file, fileList)
		{
			this.fileList.length = 0
			this.form.rule = undefined
		},
		handleImageSuccesss(response, file, fileList)
		{
			let obj = {};
			obj.url = file.response.url;
			this.form.rule = obj.url;
			this.form.fileList.push(obj);
		},
		handleRemoves(file, fileLists)
		{
			this.form.fileList.forEach((item, i) =>
			{
				if (item.url === file.url)
				{
					this.form.fileList.splice(i, 1)
				}
			})
		},
		// 取消按钮
		cancel()
		{
			this.open = false;
			this.reset();
		},
		userCancel()
		{
			this.userOpen = false;
		},
		dictCancel()
		{
			this.dictOpen = false;
		},
		userReset()
		{
			this.userParams = {
				pageNum: 1,
				pageSize: 10,
				tatal: null,
				userName: undefined,
				phone: undefined,
				branch: undefined,
				outlets: undefined,
			};
		},
		dictReset()
		{
			this.dictParams = {
				pageNum: 1,
				pageSize: 1000000,
				dictLabel: undefined,
				status: 0,
				dictType: 'sys_bussiness_type'
			};
		},
		// 表单重置
		reset()
		{
			this.form = {
				id: undefined,
				detail: undefined,
				updateBy: undefined,
				updateTime: undefined,
				type: undefined,
				score: undefined,
				chance: undefined,
				name: undefined,
				rule: undefined,
				rewards: undefined,
				disable: undefined,
				startTime: undefined,
				finishTime: undefined,
				send: undefined,
				choice: undefined,
				dispose: undefined,
				fileList: []
			};
			this.resetForm("form");
		},
		/** 搜索按钮操作 */
		handleQuery()
		{
			this.queryParams.pageNum = 1;
			this.getList();
		},
		/** 搜索按钮操作 */
		userHandleQuery()
		{
			listBank(this.userParams).then(response =>
			{
				this.userList = response.rows;

				this.getBankUsers()
			});
		},
		dictHandleQuery()
		{
			listData(this.dictParams).then(response =>
			{
				this.dictList = response.rows;
			});
		},
		// 多选框选中数据
		handleSelectionChange(selection)
		{
			this.userIds = selection.map(item => item.id)

			console.log(selection, this.userIds);
		},
		// handleUserSelectionChange(selection) {
		// console.log(this.userList)
		// let tempArr = selection.map(item => item.bankUserId)
		// console.log(tempArr)
		// this.userIds =
		// },
		handleUserSelectionChange1(a, b)
		{
			let tempArr = a.map(item => item.bankUserId)
			let look = null
			tempArr.forEach(item =>
			{
				if (item === b.bankUserId)
				{
					look = b.bankUserId
				}
			})

			if (look)
			{
				this.userIds.push(look)
			} else
			{
				let fixarr = []
				this.userIds.forEach(item =>
				{
					if (item != b.bankUserId)
					{
						fixarr.push(item)
					}
				})
				this.userIds = fixarr
			}
		},
		handleUserSelectionChange2(a)
		{
			if (!a.length)
			{
				let temp1 = this.userList.map(v => v.bankUserId)
				let tempArr1 = []
				this.userIds.forEach(v1 =>
				{
					let temp = null
					temp1.forEach(v2 =>
					{
						if (v1 === v2)
						{
							temp = v2
						}
					})
					if (!temp)
					{
						tempArr1.push(v1)
					}
				})
				this.userIds = tempArr1
				return
			}
			let tempArr = a.map(item => item.bankUserId)
			tempArr.forEach(v =>
			{
				if (!this.userIds.includes(v))
				{
					this.userIds.push(v)
				}
			})
		},
		handleDictSelectionChange(selection)
		{
			console.log('选中', selection);
			//this.dictIds = selection.map(item => item.dictCode)
			this.dictIds = selection;
		},
		/** 重置按钮操作 */
		resetQuery()
		{
			console.log('重置', this.resetForm);
			console.log(this.$refs.queryForm);
			this.resetForm("queryForm");
			this.handleQuery();
		},
		resetDictQuery()
		{
			console.log('---------------', this.$refs.dictForm);
			this.resetForm("dictForm");
			this.dictHandleQuery();
		},

		/** 新增按钮操作 */
		handleAdd()
		{
			this.reset();
			this.open = true;
			this.title = "添加活动";
		},
		/** 修改按钮操作 */
		handleUpdate(row)
		{
			this.reset();
			const id = row.id || this.ids
			getCompany(id).then(response =>
			{
				this.form = response.data;
				let obj = {};
				obj.url = this.form.rule;
				this.form.fileList = [];
				this.form.fileList.push(obj);
				this.open = true;
				this.title = "修改活动";
			});
		},
		handleUserUpdate(row)
		{
			this.userReset();
			this.handleUserUpdate1(row)
			this.userParams.companyId = row.id;
			this.userOpen = true;
		},
		handleUserUpdate1()
		{
			listBank(this.userParams).then(response =>
			{
				// this.$refs.multipleTable.clearSelection();
				this.userList = response.rows;

				this.userParams.tatal = response.total

				this.getBankUsers()
			});
		},
		getBankUsers()
		{
			let _this = this;
			getBankUsers(this.userParams.companyId).then(response =>
			{
				_this.$refs.multipleTable.clearSelection();
				this.userIdsObj = response.data || [];
				this.userIds = this.userIdsObj.map(v => v.bankUserId)
				let userIdss = this.userIds;
				this.userList.forEach(data =>
				{
					// alert(data.bankUserId);
					// alert(userIdss);
					if (userIdss.indexOf(data.bankUserId) >= 0)
					{
						_this.$refs.multipleTable.toggleRowSelection(data, true);
					}
				})
			})
		},
		handleDictUpdate(row)
		{
			console.log('配置立减金', row.id);
			this.configForm.companyId = row.id;


			// console.log(row.choice)
			this.choiceFlag = row.choice
			this.dictReset();
			this.dictParams.companyId = row.id;
			this.dictOpen = true;
			let _this = this;
			listData(this.dictParams).then(response =>
			{
				this.$refs.multipleTables.clearSelection();
				this.dictList = response.rows;
				/* getBankDicts(row.id).then(response =>
				{
					_this.$refs.multipleTables.clearSelection();
					let dictIdsObj = response.data || [];
					this.dictIds = dictIdsObj.map(v1 => v1.dictCode)
					let dictIdss = this.dictIds;
					this.dictList.forEach((data, index, arr) =>
					{
						if (dictIdss.indexOf(data.dictCode) >= 0)
						{
							_this.$refs.multipleTables.toggleRowSelection(data, true);
						}

						data.chance = 0

						dictIdsObj.forEach(v1 =>
						{
							if (v1.dictCode === data.dictCode)
							{
								data.chance = v1.chance
								arr[ index ] = data
							}
						})
					})
				}) */
			});
		},
		/** 提交按钮 */
		submitForm: function ()
		{
			this.$refs[ "form" ].validate(valid =>
			{
				if (valid)
				{
					if (this.form.id != undefined)
					{
						updateCompany(this.form).then(response =>
						{
							if (response.code === 200)
							{
								this.msgSuccess("修改成功");
								this.open = false;
								this.getList();
							} else
							{
								this.msgError(response.msg);
							}
						});
					} else
					{
						addCompany(this.form).then(response =>
						{
							if (response.code === 200)
							{
								this.msgSuccess("新增成功");
								this.open = false;
								this.getList();
							} else
							{
								this.msgError(response.msg);
							}
						});
					}
				}
			});
		},
		submitUserForm: function ()
		{
			addBankUser(this.userIds, this.userParams.companyId).then(response =>
			{
				if (response.code === 200)
				{
					this.msgSuccess("修改成功");
					this.userOpen = false;
				} else
				{
					this.msgError(response.msg);
				}
			});
		},
		submitDictForm: function ()
		{ // 配置立减金确认按钮

			console.log(this.dictIds);

			if (!this.dictIds.length)
			{
				this.msgError('请至少选择1条字典项');
				return;
			}

			//this.dictOpen = false;
			this.dictNumOpen = true;

			let list = JSON.parse(JSON.stringify(this.dictIds));
			list.map(item => item.num = null);

			//this.dictIds.length = 0;
			this.dictNumData = list;

			/* let fixarr = []

			this.dictIds.forEach(v1 =>
			{
				this.dictList.forEach(v2 =>
				{
					if (v1 === v2.dictCode)
					{
						fixarr.push({
							chance: v2.chance,
							dictCode: v2.dictCode
						})
					}
				})
			})

			let count = 0
			fixarr.forEach(item =>
			{
				let temp = item.chance || 0
				count = parseInt(count) + parseInt(temp)
			})

			if (count > 100)
			{
				this.msgError('所有权重总值不能大于100');
				return
			}

			addBankDicts(fixarr, this.dictParams.companyId).then(response =>
			{
				if (response.code === 200)
				{
					this.msgSuccess("修改成功");
					this.dictOpen = false;
				} else
				{
					this.msgError(response.msg);
				}
			}); */
		},
		/** 删除按钮操作 */
		handleDelete(row)
		{
			const ids = row.id || this.ids;
			this.$confirm('是否删除该活动?', "警告", {
				confirmButtonText: "确定",
				cancelButtonText: "取消",
				type: "warning"
			}).then(function ()
			{
				return delCompany(ids);
			}).then(() =>
			{
				this.getList();
				this.msgSuccess("删除成功");
			}).catch(function ()
			{
			});
		},
		/** 导出按钮操作 */
		handleExport()
		{
			const queryParams = this.queryParams;
			this.$confirm('是否确认导出所有【请填写功能名称】数据项?', "警告", {
				confirmButtonText: "确定",
				cancelButtonText: "取消",
				type: "warning"
			}).then(function ()
			{
				return exportCompany(queryParams);
			}).then(response =>
			{
				this.download(response.msg);
			}).catch(function ()
			{
			});
		},
		submitDictNumForm()
		{
			let list = this.dictNumData.map(item =>
			{
				return {
					companyId: this.configForm.companyId,
					dictCode: item.dictCode,
					num: item.num
				}
			});

			createCompanyCode({ exchangeList: list }).then(response =>
			{
				this.dictNumOpen = false;
				this.dictNumData.length = 0;

				this.dictOpen = false;
				this.dictIds.length = 0;

				this.handleExchange(this.configForm.companyId);

				this.msgSuccess("修改成功");
			});
		},
		dictNumCancel()
		{
			this.dictNumOpen = false;
			this.dictNumData.length = 0;
		},
		handleExchange(id)
		{
			this.$router.push({ path: '/exchange/list/' + id })
		}
	}
};
</script>


<style scoped>
.dialog-footer1 {
	display: flex;
	justify-content: space-between;
	align-items: center;
}
</style>
